<?php
//getUserCurrLocation(28.5967627,77.3406156);
if (isset($_GET['action'])){
	// Retrieve the GET parameters and executes the function
	  $funcName	 = $_GET['action'];
	  $vars	  = $_GET['vars'];
	  $funcName($vars); 
	 }
	 else if (isset($_POST['action'])){
	  // Retrieve the POST parameters and executes the function
	  $funcName	 = $_POST['action'];
	$vars	  = $_POST['vars'];
	$funcName($vars); 
	  
	 } else {
	  // If there is no action in the URL, then do this
	echo "<INPUT NAME='btnSubmitAdmin' TYPE='button' ONCLICK='javascript:javaFunction()' VALUE='Call Javafunction() which redirects to a PHP function'>";
   }
function getUserCurrLocation($loc)
{
//alert($loc);
$request =  'http://maps.googleapis.com/maps/api/geocode/json?latlng='.$loc.'&sensor=true';
$response = file_get_contents($request);
//print_r ($loc);
if ($response === false) {
	die('Request failed');
} else
{
$jsondata = json_decode($response,true);
 //print_r($jsondata);
if(is_array($jsondata )&& $jsondata['status']=='OK')
{
      $addr = $jsondata ['results'][0]['formatted_address'];
	  print "<b>". $addr ."</b> | View it on <a href='Location.html?pos=" . $loc . "' target='_blank'>Map</a>";
} else
{
 print 'Unable to get Address';
}
}
}
?>
<SCRIPT language="javascript">
	var address = "";
	var lt="";
	var lg="";
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(success);
        } else {
            alert("Geo Location is not supported on your current browser!");
        }
        function success(position) {
            lt = position.coords.latitude;
            lg = position.coords.longitude;
            //address = lat + "," + long;
            //GetLoc(pos);
        }
   function javaFunction(){
	// In the varArray are all the variables you want to give with the function
	//var varArray = new Array();
	var varArray = lt+","+lg;
	//varArray[1] = lg;
   
	// the url which you have to reload is this page, but you add an action to the GET- or POST-variable
	var url="http://localhost:8080/Medical/Common/getUserLocation.php?action=getUserCurrLocation&vars="+varArray;
	
	// Opens the url in the same window
	   window.open(url, "_self");
	  }
  </SCRIPT>